<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
	protected function _initDb()
	{		
		$optionResources = $this->getOption('resources');
		$dbOption = $optionResources['db'];
		$dbOption['params']['username'] = 'root';
		$dbOption['params']['password'] = '';
		$dbOption['params']['dbname'] = 'zend';
		
		$adapter = $dbOption['adapter'];
		$config = $dbOption['params'];
		
		$db = Zend_Db::factory($adapter, $config);
		$db->setFetchMode(Zend_Db::FETCH_ASSOC);
		$db->query("SET NAMES 'utf8'");
		$db->query("SET CHARACTER SET 'utf8'");
		
		Zend_Registry::set('connectDb', $db);
		Zend_Db_Table::setDefaultAdapter($db);
		return $db;
	}
	
	protected function _initSession()
	{
		$config = array(
			'name'           		=> 'session',
			'primary'        		=> 'id',
			'modifiedColumn' 	=> 'modified',
			'dataColumn'     	=> 'data',
			'lifetimeColumn' 	=> 'lifetime',
			'lifetime'			=> 60*5, // 5minutes
			'overrideLifetime' 	=> false
		);
		
		Zend_Session::setSaveHandler(new Zend_Session_SaveHandler_DbTable($config));
		Zend_Session::start();
		return $this;
	}
	
	protected function _initLocale()
	{
		$locale = new Zend_Locale('vi_VN');
		Zend_Registry::set('Zend_Locale', $locale);
		return $this;
	}
	
	protected function _initFrontcontroller()
	{
		$front = Zend_Controller_Front::getInstance();
		$front->addModuleDirectory(APPLICATION_PATH . '/modules');
		$front->setDefaultModule('default');
		$front->registerPlugin(new Zendvn_Plugin_Permission());
		return $front;
	}
}